package com.cosina.game.crystallight.ui.battle.drawable;

import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;

import com.cosina.game.crystallight.engine.BattleEngine;
import com.cosina.game.crystallight.engine.Sheild;
import com.cosina.game.crystallight.engine.ManaFlask;
import com.cosina.game.crystallight.model.battle.BattleField;
import com.cosina.game.crystallight.ui.battle.BattleResource;
import com.cosina.game.crystallight.ui.battle.drawadapter.BaseDrawable;
import com.cosina.game.crystallight.ui.common.PaintSuite;
import com.cosina.game.crystallight.util.CanvasUtil;

public class HpAndManeAndScoreDrawable extends BaseDrawable{

	
	final Point hpTextLocationAbout = new Point();
	final int ManeBarTotalLength = 196;
	
	final Point maneBarLocationAbout = new Point(11,480-24 -5);
	final Point maneNumberLocationAbout = new Point(110,480 - 15);
	final Point scoreLocationAbout = new Point(272,480 - 15);
	
	public HpAndManeAndScoreDrawable(){
		BattleField field = BattleEngine.field;
		
		Point door = field.getCastleArea()[1];
		hpTextLocationAbout.set((door.x+1)*44-18, 5 + door.y*44 + 19);
	}
	
	
	@Override
	public void draw(Canvas canvas) {
		{
			Sheild hpManager = BattleEngine.sheild;
			String str = hpManager.getQuantity();
			CanvasUtil.drawText(canvas, str, hpTextLocationAbout.x, hpTextLocationAbout.y, PaintSuite.p4Text, 16);
		}
		
		{
			ManaFlask maneManager = BattleEngine.manaFlask;
			int currentMane = maneManager.getCurrent();
			float percent = maneManager.getPercent();
			if(percent > 0 ){
				int drawLength = (int)(ManeBarTotalLength * percent);
				try{
					manaBarRect.set(0, 0, drawLength, 18);
					manaBarToRect.set(maneBarLocationAbout.x,maneBarLocationAbout.y,maneBarLocationAbout.x + drawLength,maneBarLocationAbout.y + 18);
					canvas.drawBitmap(BattleResource.manaBar, manaBarRect,manaBarToRect, PaintSuite.p4Simple);
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			String str = currentMane + " / " + maneManager.getMax();
			CanvasUtil.drawText(canvas, str, maneNumberLocationAbout.x, maneNumberLocationAbout.y, PaintSuite.p4Text, 16);
		}
		{
			String battleScore = BattleEngine.statistics.battleScore + "";
			CanvasUtil.drawText(canvas, battleScore, scoreLocationAbout.x, scoreLocationAbout.y, PaintSuite.p4Text, 16);
		}
	}
	
	private final Rect manaBarRect = new Rect();
	private final Rect manaBarToRect = new Rect();
}
